<template>
    <Row>
        <Col span="22" offset="1">
            <Form ref="FreezeMoney" :model="FreezeMoney" :rules="ruleValidate" :label-width="135" :style="{marginTop: '30px'}">
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="冻结编码">
                            <Input v-model="FreezeMoney.NumCode" readonly placeholder="流水编码由系统自动生成" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                
                <Divider orientation="left">冻结银行</Divider>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="冻结银行" prop="BankName">
                            <!-- <Input  v-model.trim="BankName" placeholder="例如：中国流水上海分行" >
                                <Button slot="append" @click="ShowDialog = true" icon="ios-search"></Button>
                            </Input> -->
                            <AutoComplete
                                v-model="FreezeMoney.BankName"
                                icon="ios-search"
                                placeholder="请输入冻结银行名称！"
                                clearable
                                @on-search="SearchBank"
                                @on-select="SelectBank"
                                @on-clear="ClearBank"
                                style="width:100%">
                                <div class="auto-complete-item" v-for="item in Banks" :key="item.OrderNum">
                                    <div class="auto-complete-group">
                                        <span>{{ item.Company }}</span>
                                        <!-- <a href="https://www.baidu.com/search?q=iView" target="_blank">更多</a> -->
                                    </div>
                                    <Option v-for="option in item.Children" :value="option.Id" :key="option.Id">
                                        <span class="auto-complete-title">{{ option.Name }}</span>
                                        <span class="auto-complete-count">{{ option.Account.substr(option.Account.length-4,4) }} 账户尾号</span>
                                    </Option>
                                </div>
                                <!-- <a href="https://www.baidu.com/" target="_blank" class="auto-complete-more">查看所有结果</a> -->
                            </AutoComplete>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="冻结账户" prop="BankAccount">
                            <Input v-model.trim="FreezeMoney.BankAccount" readonly placeholder="例如：620000xxxxxxxxxx7843"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="账户尾号">
                            <Input v-model.trim="AccountTail" readonly placeholder="填写流水账户后自动计算取最后四位，例如：7843" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="账户性质"  prop="AccountType">
                            <!-- <Input v-model.trim="AccountType" readonly placeholder="例如：直营账户、一般账户" ></Input> -->
                            <Select v-model.trim="AccountType" filterable disabled >
                                <Option v-for="item in AccountTypes" :value=item.value :key="item.value">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>

                <Divider orientation="left">冻结项目</Divider>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="项目编码" prop="ProjectCode">
                            <!-- <Input v-model="FreezeMoney.ProjectCode" placeholder="请选择项目编码" >
                                <Button slot="append" @click="ShowDialog = true" icon="ios-search"></Button>
                            </Input> -->
                            <AutoComplete
                                v-model="FreezeMoney.ProjectCode"
                                icon="ios-search"
                                clearable
                                @on-search="SearchProject"
                                @on-select="SelectProject"
                                @on-clear="ClearProject"
                                placeholder="请输入涉案项目名称！"
                                style="width:100%">
                                <div class="auto-complete-item" v-for="item in Projects" :key="item.OrderNum">
                                    <div class="auto-complete-group">
                                        <span>{{ item.Company }}</span>
                                        <a href="#">更多</a>
                                    </div>
                                    <Option v-for="option in item.Children" :value="option.Id" :key="option.Id">
                                        <span class="auto-complete-title"> {{ option.Name }} </span>
                                        <span class="auto-complete-count"> {{ option.NumCode }} 项目编码</span>
                                    </Option>
                                </div>
                               <!--  <a href="https://www.baidu.com/search?q=iView" target="_blank" class="auto-complete-more">查看所有结果</a> -->
                            </AutoComplete>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="涉案项目" prop="ProjectName">
                            <Input  v-model.trim="FreezeMoney.ProjectName" readonly placeholder="例如：杭州之江云镜二标" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="冻结确认" prop="FreezeConfirm">
                            <Select v-model="FreezeMoney.FreezeConfirm" >
                                <Option v-for="item in FreezeConfirm" :value=item.value :key="item.label">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10" offset="2">
                        <FormItem label="项目经理" prop="ProjectManager">
                            <Input  v-model.trim="FreezeMoney.ProjectManager" placeholder="例如：毛XX" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="身份证号" prop="ProjectManagerID">
                            <Input  v-model.trim="FreezeMoney.ProjectManagerID" placeholder="例如：330681xxxxxxxx1678" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="分公司" prop="Company">
                            <!-- <Input v-model.trim="Company" readonly placeholder="例如：绍兴分公司、杭州分公司、宁波分公司" ></Input> -->
                            <Select v-model.trim="Company" filterable disabled >
                                <Option v-for="item in Companys" :value=item.value :key="item.Id">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="工程类型" prop="ItemType">
                            <!-- <Input v-model.trim="ItemType" readonly placeholder="例如：土建、消防、涂料、其他" ></Input> -->
                            <Select v-model.trim="ItemType" filterable disabled >
                                <Option v-for="item in ProjectTypes" :value=item.value :key="item.Id">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="20" offset="2">
                        <FormItem label="项目地块" prop="LandParcel">
                            <Input v-model.trim="LandParcel" readonly placeholder="例如：3#地块" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Divider orientation="left">法院诉讼</Divider>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="案号" prop="CaseCode">
                            <Input v-model.trim="FreezeMoney.CaseCode" placeholder="例如：2020浙1125执2628" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="受理法院" prop="AccpectCourt">
                            <Input v-model.trim="FreezeMoney.AccpectCourt" placeholder="例如：浙江省诸暨市人民法院" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="上诉原告" prop="Plaintiff">
                            <Input v-model.trim="FreezeMoney.Plaintiff" placeholder="例如：宿州市隆腾建筑工程有限公司" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="判决时间" prop="JudgmentTime">
                            <DatePicker v-model.trim="FreezeMoney.JudgmentTime" format="yyyy-MM-dd"  type="date" placeholder="请选择时间！" style="width: 100%"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="履行期限" prop="DeadLine">
                            <DatePicker v-model.trim="FreezeMoney.DeadLine" format="yyyy-MM-dd"  type="date" placeholder="请选择时间！" style="width: 100%"></DatePicker>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="案件状态" prop="CaseStatus">
                            <Select v-model.number="FreezeMoney.CaseStatus" >
                                <Option v-for="item in CaseStatus" :value=item.value :key="item.value">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="指令冻结" prop="CourtFreeze">
                            <Input v-model.number="FreezeMoney.CourtFreeze" placeholder="法院指令冻结金额" >
                                <span slot="suffix"><i>元</i ></span>
                                <Icon type="logo-yen" slot="prefix" />
                            </Input>
                        </FormItem>
                    </Col>
                    <Col span="10" offset="2">
                        <FormItem label="实际冻结" prop="FactFreeze">
                            <Input v-model.number="FreezeMoney.FactFreeze" placeholder="实际冻结金额" >
                                <span slot="suffix"><i>元</i ></span>
                                <Icon type="logo-yen" slot="prefix" />
                            </Input>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="判决金额" prop="JudgmentMoney">
                            <Input v-model.number="FreezeMoney.JudgmentMoney" placeholder="法院判决金额" >
                                <span slot="suffix"><i>元</i ></span>
                                <Icon type="logo-yen" slot="prefix" />
                            </Input>
                        </FormItem>
                    </Col>
                </Row>
                <Divider orientation="left">冻结资金</Divider>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="冻结金额(小写)" prop="Amount">
                            <Input v-model.number="FreezeMoney.Amount" placeholder="实际发生的金额" >
                                <span slot="suffix"><i>元</i ></span>
                                <Icon type="logo-yen" slot="prefix" />
                            </Input>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="冻结金额(大写)" prop="BigAmount">
                            <Input v-model.trim="BigMoney" readonly placeholder="实际发生的金额" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="判决结果">
                            <Select v-model.number="FreezeMoney.JudgeResult" >
                                <Option v-for="item in JudgeResults" :value=item.value :key="item.value">{{ item.label }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="分管项目财务" prop="Accountant">
                            <Input v-model.trim="FreezeMoney.Accountant" placeholder="例如：赵烨" ></Input>
                        </FormItem>
                    </Col>
                    <Col span="10" offset="2">
                        <FormItem label="冻结落实人" prop="FreezeOperator">
                            <Input v-model.trim="FreezeOperator" disabled placeholder="例如：赵烨" ></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="冻结时间" prop="FreezeTime">
                            <DatePicker v-model.trim="FreezeMoney.FreezeTime" format="yyyy-MM-dd"  type="date" placeholder="请选择时间！" style="width: 100%"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="解冻时间" prop="UnFreezeTime">
                            <DatePicker v-model.trim="FreezeMoney.UnFreezeTime" format="yyyy-MM-dd"  type="date" placeholder="请选择时间！" style="width: 100%"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="10" offset="2">
                        <FormItem label="冻结天数" prop="FreezeDayCount">
                            <Input readonly v-model.trim="FreezeMoney.FreezeDayCount" placeholder="例如：5" >
                                <span slot="suffix"><i>天</i ></span>
                            </Input>
                        </FormItem>
                    </Col>
                    <Col span="10" >
                        <FormItem label="冻结利率" prop="FreezeRate">
                            <Input v-model.number="FreezeMoney.FreezeRate" placeholder="例如：6、10、12" >
                                <Select v-model="FreezeMoney.FreezeRateType" slot="prepend" style="width: 80px">
                                    <Option value="DAY">日</Option>
                                    <Option value="MONTH">月</Option>
                                    <Option value="YEAR">年</Option>
                                </Select>
                                <span slot="append"><i>%</i ></span>
                            </Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10" offset="2">
                        <FormItem label="应确认利息" prop="FreezeInterest">
                            <Input readonly v-model.number="FreezeMoney.FreezeInterest" placeholder="例如：564612.45" >
                                <span slot="suffix"><i>元</i ></span>
                            </Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="20" offset="2">
                        <FormItem label="备注" prop="Remark">
                            <Input v-model="FreezeMoney.Remark" maxlength="250" type="textarea" :autosize="{minRows: 5,maxRows: 5}" show-word-limit placeholder="请输入冻结资金备注！"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="20" offset="2">
                        <FormItem label="">
                            <Button @click="CreditContract" type="primary">生成借条</Button>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="20" offset="2">
                        <FormItem label="借条档案" prop="Summary">
                            <Upload
                                :headers="UploadHeader"
                                type="drag"
                                :data="UploadParmas"
                                :paste="true"
                                :action="UploadURL"
                                :before-upload="BeforeUpload"
                                :on-remove="RemoveUpload"
                                accept=".pdf">
                                <div style="padding: 20px 0;text-align:center">
                                    <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                                    <p style="text-align:center;font-size:small;color:black">单击或拖拽至此上传文件</p>
                                </div>
                            </Upload>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="20" offset="2" style="text-align:center;margin-top:58px">
                        <Button type="primary" @click="Submit('FreezeMoney')">提交</Button>
                        <Button @click="Reset('FreezeMoney')" style="margin-left: 108px">重置</Button>
                    </Col>
                </Row>
            </Form>
        </Col>
    </Row>
</template>
<script>
import { mapState } from "vuex";
import 
{ 
    CreateCode,
    GetOne,
    Create,
    Update,
    QueryBankInfo,
    QueryProjectInfo,
    QueryBankById,
    QueryProjectById,
    QueryAdministrativeByCode,
    LoadBankType,
    LoadProjectType,
    LoadCompany,
    ComputeFreezeDayCount,
    ComputeInterest,
    CheckIDNumber,
    DeleteUploadFile,
} from '@/axios/api/FreezeMoneyAPI'
import { BigMoney } from '@/axios/api/BankAPI'
import { GetOne as GetUser } from '@/axios/api/UsersAPI'
import { getUserInfo,getToken } from '@/store/localStorage/cookies';
import qs from 'qs'

export default {
    computed:{
        ...mapState('freezemoney',[
            'currentFreezeMoneyID',
            'pageIndex',
            'pageSize',
        ])
    },
    components: {
        
    },
    mounted: function(){
        
        //console.log(this.currentFreezeMoneyID)
        if(this.currentFreezeMoneyID != ''){
            this.$Spin.show();
        }
        setTimeout(() => {
            this.$Spin.hide();
        }, 1000);

        //获取银行类型
        LoadBankType().then(res => {
            const list = res.map(item => {
                return {
                    value: item.Code.toString(),
                    label: item.Name
                };
            });
            this.AccountTypes = list;
        })

        //获取工程项目类型
        LoadProjectType().then(res => {
            const list = res.map(item => {
                return {
                    value: item.Code.toString(),
                    label: item.Name
                };
            });
            this.ProjectTypes = list;
        })

        //获取公司列表
        LoadCompany().then(res => {
            const list = res.map(item => {
                return {
                    value: item.Code.toString(),
                    label: item.Name
                };
            });
            this.Companys = list;
        })
        
        if(this.currentFreezeMoneyID != ''){
            GetOne(this.currentFreezeMoneyID).then(res => {
                this.FreezeMoney.Id = res.Id;
                this.FreezeMoney.Num = res.Num;
                this.FreezeMoney.NumCode = res.NumCode;
                this.FreezeMoney.FreezeBank = res.FreezeBank;
                this.FreezeMoney.FreezeProject = res.FreezeProject;
                this.FreezeMoney.FreezeConfirm = res.FreezeConfirm;
                this.FreezeMoney.CaseCode = res.CaseCode;
                this.FreezeMoney.CaseStatus = res.CaseStatus;
                this.FreezeMoney.AccpectCourt = res.AccpectCourt;
                this.FreezeMoney.Plaintiff = res.Plaintiff;
                this.FreezeMoney.CourtFreeze = res.CourtFreeze;
                this.FreezeMoney.JudgmentMoney = res.JudgmentMoney;
                this.FreezeMoney.FundsType = res.FundsType;
                this.FreezeMoney.ProjectManager = res.ProjectManager;
                this.FreezeMoney.ProjectManagerID = res.ProjectManagerID;
                this.FreezeMoney.Accountant = res.Accountant;
                this.FreezeMoney.JudgmentTime = res.JudgmentTime;
                this.FreezeMoney.Remark = res.Remark;
                this.FreezeMoney.DeadLine = res.DeadLine;
                this.FreezeMoney.FreezeTime = res.FreezeTime;
                this.FreezeMoney.UnFreezeTime = res.UnFreezeTime;
                this.FreezeMoney.FreezeDayCount = res.FreezeDayCount;
                this.FreezeMoney.FreezeInterest = res.FreezeInterest;
                this.FreezeMoney.FreezeRate = res.FreezeRate;
                this.FreezeMoney.FreezeRateType = res.FreezeRateType;
                this.FreezeMoney.JudgeResult = res.JudgeResult;
                this.FreezeMoney.Amount = res.Amount;
                this.FreezeMoney.FreezeOperatorId = res.FreezeOperatorId;
                this.FreezeMoney.CreateTime = res.CreateTime;

                
            });
            
        }
        else{
            CreateCode().then(res => {
                console.log(res);
                this.FreezeMoney.NumCode = res.toString();
            })

            if(this.FreezeMoney.Id == '00000000-0000-0000-0000-000000000000'){
                var currentUserInfo = JSON.parse(getUserInfo());
                this.FreezeOperator = currentUserInfo.Name;
                this.FreezeMoney.FreezeOperatorId = currentUserInfo.Id;
            }
            else{
                GetUser(this.FreezeMoney.FreezeOperatorId).then(res => {
                    console.log(res);
                    this.FreezeOperator = res.RealName;
                })
            }
        }
    },
    data () {
        const ValidateIDnumber = (rule,value,callback) => {

            if(value == ''){
                callback(new Error("项目经理身份证号码为必填项！"));
            }
            else if (value.length < 18) {
                callback(new Error('身份证号码不足18位！'));
            }
            else {
                CheckIDNumber({IDNumberStr: value}).then(res => {
                    (res === value) ? callback() : callback(new Error('身份证号码校验不通过！'))
                })
            }

        };
        return {
            FreezeMoney: {
                Id: '00000000-0000-0000-0000-000000000000',
                Num: 1,
                NumCode: '',
                FreezeBank: '00000000-0000-0000-0000-000000000000',
                BankName: '',
                FreezeProject: '00000000-0000-0000-0000-000000000000',
                ProjectCode: '',
                ProjectName: '',
                FreezeConfirm: 0,
                CaseCode: '',
                AccpectCourt: '',
                CaseStatus: 0,
                Plaintiff: '',
                CourtFreeze: 0.0,
                JudgmentMoney: 0.0,
                ProjectManager: '',
                ProjectManagerID: '',
                Accountant: '',
                JudgmentTime: new Date(),
                Remark: '',
                DeadLine: new Date(),
                FreezeTime: new Date(),
                UnFreezeTime: new Date("9999-12-31"),
                FreezeDayCount: 0,
                FreezeInterest: 0.0,
                FreezeRate: 0.0,
                FreezeRateType: "MONTH",
                JudgeResult: 0,
                FundsType: '',
                Amount: 0.0,
                FreezeOperatorId: '00000000-0000-0000-0000-000000000000',
                CreateTime: new Date()
            },
            ruleValidate: {
                //Num: [{ type: 'number', message: '只能输入数字', trigger: 'blur' }],
                BankName: [{ required: true, message: '冻结银行为必填项！', trigger: 'blur' }],
                Amount: [{ required: true,type: 'number', message: '只能输入数字', trigger: 'blur' }],
                ProjectCode: [{ required: true, message: '涉案项目编码为必填项！', trigger: 'blur' }],
                ProjectName: [{ required: true, message: '涉案项目名称为必填项！', trigger: 'blur' }],
                ProjectManager: [{ required: true, message: '项目经理为必填项！', trigger: 'blur' }],
                CaseCode: [{ required: true, message: '案号为必填项！', trigger: 'blur' }],
                ProjectManagerID: [{ validator: ValidateIDnumber,required: true, trigger: 'blur'}]
            },
            JudgeResults:[
                {
                    value: 0,
                    label: "审判中"
                },
                {
                    value: 1,
                    label: "胜诉"
                },
                {
                    value: 2,
                    label: "败诉"
                }
            ],
            FreezeConfirm: [
                {
                    value: 0,
                    label: "待确认"
                },
                {
                    value: 1,
                    label: "已确认"
                }
            ],
            CaseStatus:[
                {
                    value: 0,
                    label: "诉前保全"
                },
                {
                    value: 1,
                    label: "传票送达"
                },
                {
                    value: 2,
                    label: "应诉阶段"
                },
                {
                    value: 3,
                    label: "履行期间"
                },
                {
                    value: 4,
                    label: "执行阶段"
                },
                {
                    value: 5,
                    label: "案件结案"
                }
            ],
            UploadHeader: {
                Authorization: getToken(),
                "Access-Control-Allow-Origin": '*',
                "Access-Control-Allow-Methods": '*',
                "Access-Control-Allow-Credentials": true
            },
            UploadURL: process.env.VUE_APP_BASE_API + '/FreezeMoney/UploadImportFile/',
            //UploadURL: process.env.VUE_APP_BASE_NAS + '/entry.cgi',
            UploadParmas: {
                FreezeTime: '',
                ProjectManager: '',
                ProjectManagerID: '',
            },
            NASLoginStatus: false,
            ProjectTypes: [],
            AccountTypes: [],
            Companys:[],
            Banks: [],
            Projects: [],
            ShowDialog: false,
            callmodal: "FreezeMoney-Sheet",
            Province:[],
            City:[],
            Zone:[],
            ProvinceStatus: false,
            CityStatus: false,
            ZoneStatus: false,
            BankName: '',
            AccountTail: '',
            AccountType: '',
            ProjectProvince: '',
            ProjectCity: '',
            ProjectZone: '',
            ProjectCode: '',
            ProjectName: '',
            Company: '',
            ItemType: '',
            LandParcel: '',
            DetailAddress:'',
            FreezeOperator: '',
            Address: '',
            BigMoney:''
        }
    },
    watch: {
        'FreezeMoney.Account'(value){
            if(value != '' && value != null){
                this.AccountTail = value.substr(value.length-4,4);
            }
        },
        'FreezeMoney.FactFreeze'(value){
            this.FreezeMoney.Amount = value;
        },
        'FreezeMoney.Amount'(value){
            if(value != '' && value != null){
                BigMoney(value).then(res => {
                    this.BigMoney = res;
                })
                this.FreezeMoney.FactFreeze = value;
                ComputeInterest({
                    FreezeTime: this.FreezeMoney.FreezeTime,
                    UnFreezeTime:  this.FreezeMoney.UnFreezeTime,
                    Amount:  this.FreezeMoney.Amount,
                    FreezeRate: this.FreezeMoney.FreezeRate,
                    FreezeRateType: this.FreezeMoney.FreezeRateType
                }).then(res => {
                    this.FreezeMoney.FreezeInterest = res;
                })
            }
        },
        'FreezeMoney.FreezeBank'(value){
            QueryBankById(value).then(res => {
                if(res){
                    this.FreezeMoney.FreezeBank = res.Id;
                    this.FreezeMoney.BankAccount = res.Account;
                    this.FreezeMoney.BankName = res.Name;
                    this.AccountTail = res.Account.substr(res.Account.length-4,4);
                    this.AccountType = res.AccountType;
                }
            })
        },
        'FreezeMoney.FreezeProject'(value){
            QueryProjectById(value).then(projectres => {
                this.FreezeMoney.FreezeProject = projectres.Id;
                this.FreezeMoney.ProjectCode = projectres.NumCode;
                this.FreezeMoney.ProjectName = projectres.Name;

                //开始查询省份
                QueryAdministrativeByCode(projectres.Province).then(provinceres => {
                    const one =  {
                        value: provinceres.Code.toString(),
                        label: provinceres.Name,
                        Id: provinceres.Id
                    };

                    if(this.Province.indexOf(item => item.Id = one.Id) === -1){
                        this.Province.push(one);
                    }

                    //开始查询城市
                    QueryAdministrativeByCode(projectres.City).then(cityres => {
                        if(cityres){
                            //console.log(cityres);
                            const one =  {
                                value: cityres.Code.toString(),
                                label: cityres.Name,
                                Id: cityres.Id
                            };

                            if(this.City.indexOf(item => item.Id = one.Id) === -1){
                                this.City.push(one);
                            }
                            
                        }

                        //开始查询地区
                        QueryAdministrativeByCode(projectres.Zone).then(zoneres => {
                            if(zoneres){
                                //console.log(zoneres)
                                const one =  {
                                    value: zoneres.Code.toString(),
                                    label: zoneres.Name,
                                    Id: zoneres.Id
                                };

                                if(this.Zone.indexOf(item => item.Id = one.Id) === -1){
                                    this.Zone.push(one);
                                }
                            }
                        })
                        //结束查询地区
                    })
                    //结束查询城市
                })
                //结束查询省份
                
                this.ProjectProvince = projectres.Province;
                this.ProjectCity = projectres.City;
                this.ProjectZone = projectres.Zone;
                this.Company = projectres.Company;
                this.ItemType = projectres.ItemType;
                this.LandParcel = projectres.LandParcel;
                this.DetailAddress = projectres.DetailAddress;
            })
        },
        'FreezeMoney.FreezeTime'(value){
            ComputeFreezeDayCount({
                FreezeTime: value,
                UnFreezeTime: this.FreezeMoney.UnFreezeTime
            }).then(res => {
                this.FreezeMoney.FreezeDayCount = res;
            });
        },
        'FreezeMoney.UnFreezeTime'(value){
            ComputeFreezeDayCount({
                FreezeTime: this.FreezeMoney.FreezeTime,
                UnFreezeTime: value
            }).then(res => {
                this.FreezeMoney.FreezeDayCount = res;
            });
        },
        'FreezeMoney.FreezeDayCount'(){
            ComputeInterest({
                FreezeTime: this.FreezeMoney.FreezeTime,
                UnFreezeTime:  this.FreezeMoney.UnFreezeTime,
                Amount:  this.FreezeMoney.Amount,
                FreezeRate: this.FreezeMoney.FreezeRate,
                FreezeRateType: this.FreezeMoney.FreezeRateType
            }).then(res => {
                this.FreezeMoney.FreezeInterest = res;
            })
        },
        'FreezeMoney.FreezeRateType'(newValue,oldValue){
            if(oldValue == "DAY" && newValue == "MONTH"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*100*30.0)/100
            }

            if(oldValue == "MONTH" && newValue == "YEAR"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*100*12.0)/100
            }

            if(oldValue == "DAY" && newValue == "YEAR"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*100*360.0)/100
            }

            if(oldValue == "YEAR" && newValue == "MONTH"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*100/12.0)/100
            }

            if(oldValue == "YEAR" && newValue == "DAY"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*10000/360.0)/10000
            }

            if(oldValue == "MONTH" && newValue == "DAY"){
                this.FreezeMoney.FreezeRate = Math.round(this.FreezeMoney.FreezeRate*10000/30.0)/10000
            }

            ComputeInterest({
                FreezeTime: this.FreezeMoney.FreezeTime,
                UnFreezeTime:  this.FreezeMoney.UnFreezeTime,
                Amount:  this.FreezeMoney.Amount,
                FreezeRate: this.FreezeMoney.FreezeRate,
                FreezeRateType: newValue
            }).then(res => {
                this.FreezeMoney.FreezeInterest = res;
            })
        },
        'FreezeMoney.FreezeRate'(value){
            ComputeInterest({
                FreezeTime: this.FreezeMoney.FreezeTime,
                UnFreezeTime:  this.FreezeMoney.UnFreezeTime,
                Amount:  this.FreezeMoney.Amount,
                FreezeRate: value,
                FreezeRateType: this.FreezeMoney.FreezeRateType
            }).then(res => {
                this.FreezeMoney.FreezeInterest = res;
            })
        }
    },
    methods: {
        Submit (name){
            //this.$Message.success('按了OK键');
             this.$refs[name].validate((valid) => {
                if (valid) {
                    if(this.FreezeMoney.Id == '00000000-0000-0000-0000-000000000000'){
                        this.$Message.success('校验通过!');
                        Create(this.FreezeMoney).then(res => {
                            if(res > 0){

                                setTimeout(() => {
                                    this.$store.dispatch('freezemoney/UpdateTableAsync',{
                                        PageIndex: this.pageIndex,
                                        PageSize: this.pageSize
                                    });

                                     this.$Notice.success({
                                        title: '操作提示',
                                        desc: '保存成功！ '
                                    });
                                }, 1000)
                               
                            }
                            else{
                                this.$Notice.error({
                                    title: '操作提示',
                                    desc: '保存失败！ '
                                });
                            }
                        }).catch(err =>{
                            this.$Notice.error({
                                title: '操作提示',
                                desc: '保存失败：' + err.data + '!'
                            });
                        })
                        
                    }
                    else{
                        this.$Message.success('校验通过!');
                        
                        Update(this.FreezeMoney).then(res => {
                            if(res > 0){
                                setTimeout(() => {
                                    this.$store.dispatch('freezemoney/UpdateTableAsync',{
                                        PageIndex: this.pageIndex,
                                        PageSize: this.pageSize
                                    });

                                     this.$Notice.success({
                                        title: '操作提示',
                                        desc: '更新成功！'
                                    });
                                }, 1000)
                            }
                            else{
                                this.$Notice.success({
                                    title: '操作提示',
                                    desc: '更新失败！'
                                });
                            }
                        }).catch(err =>{
                            this.$Notice.error({
                                title: '操作提示',
                                desc: '更新失败：' + err.data + '!'
                            });
                        })
                    }
                    this.ChangeModal();
                } else {
                    this.$Message.error('校验失败!');
                    //this.ChangeModal('FreezeMoney');
                }
            })
            
        },
        Reset (name){
            this.$refs[name].resetFields();
        },
        ChangeModal (){
            //this.$refs[name].resetFields();
            this.$store.commit('freezemoney/CHANGE_MODAL');
            this.$router.push('/funds/FreezeMoney')
        },
        SearchBank(value){
            QueryBankInfo(value).then(res => {
                this.Banks = res;
            })
        },
        SelectBank(value){
            if(value){
                this.FreezeMoney.FreezeBank = value;
            }
        },
        SearchProject(value){
            QueryProjectInfo(value).then(res => {
                //console.log('>>>>>>>>>>>>>SearchProject',res);
                this.Projects = res;
            })
        },
        SelectProject(value){
            this.FreezeMoney.FreezeProject = value;
        },
        ClearBank(){
            this.FreezeMoney.FreezeBank = '00000000-0000-0000-0000-000000000000'
            this.FreezeMoney.BankAccount = '';
            this.AccountTail = '';
            this.AccountType = '';
            this.Banks = [];
        },
        ClearProject(){
            this.FreezeMoney.FreezeProject = '00000000-0000-0000-0000-000000000000'
            this.FreezeMoney.ProjectName = '';
            this.Company = '';
            this.LandParcel = '';
            this.ItemType = '';
            this.Projects = [];
        },
        CreditContract(){
            BigMoney(this.FreezeMoney.Amount).then(res => {

                this.$Spin.show();

                let link = document.createElement("a");

                var CreditContractInfo = {
                    ProjectManager: this.FreezeMoney.ProjectManager,
                    ProjectManagerID: this.FreezeMoney.ProjectManagerID,
                    Amount: this.FreezeMoney.Amount,
                    BigAmount: res,
                    FreezeRate: this.FreezeMoney.FreezeRate,
                    FreezeRateType: this.FreezeMoney.FreezeRateType,
                    FreezeTime: this.FreezeMoney.FreezeTime
                }

                link.href = process.env.VUE_APP_BASE_API + "/FreezeMoney/CreateWordContract?" + qs.stringify(CreditContractInfo, { arrayFormat: 'brackets' }); // 本窗口打开下载
                //console.log(this.QueryConstraint)

                link.download = "导出文件.docx";

                document.body.appendChild(link);

                link.click();
                
                document.body.removeChild(link);

                this.$Spin.hide();
            })
        },
        RemoveUpload(){
            DeleteUploadFile(this.HandleDataForm.Importfile);
        },
        BeforeUpload(){
            this.UploadParmas.FreezeTime = this.FreezeMoney.FreezeTime.getTime();
            this.UploadParmas.ProjectManager = this.FreezeMoney.ProjectManager;
            this.UploadParmas.ProjectManagerID = this.FreezeMoney.ProjectManagerID;
        }
    }
}
</script>
<style>
    .auto-complete-item{
        padding: 4px 0;
        border-bottom: 1px solid #F6F6F6;
    }
    .auto-complete-group{
        font-size: 12px;
        padding: 4px 6px;
        margin-bottom:7px;
    }
    .auto-complete-group span{
        color: #666;
        font-weight: bold;
    }
    .auto-complete-group a{
        float: right;
    }
    .auto-complete-count{
        float: right;
        color: #999;
    }
    .auto-complete-more{
        display: block;
        margin: 0 auto;
        padding: 4px;
        text-align: center;
        font-size: 12px;
    }
</style>